package com.tally.project.system.category.controller;

import java.util.List;

import com.tally.framework.web.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.tally.project.system.category.domain.Category;
import com.tally.project.system.category.service.ICategoryService;
import com.tally.framework.web.controller.BaseController;
import com.tally.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 账单分类Controller
 * @author soul
 * @date 2023-05-18
 */
@Api(tags = "账单分类")
@Controller
@RequestMapping("/system/category")
public class CategoryController extends BaseController
{

    @Resource
    private ICategoryService categoryService;


    /**
     * 查询账单分类列表
     */
    @ApiOperation("账单分类列表")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody Category category)
    {
        List<Category> list = categoryService.selectCategoryList(category);
        return getDataTable(list);
    }

    /**
     * 新增保存账单分类
     */
    @ApiOperation("新增账单分类")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody Category category)
    {
        return toAjax(categoryService.insertCategory(category));
    }

    /**
     * 账单分类
     */
    @ApiOperation("修改账单分类")
    @GetMapping("/edit/{id}")
    @ResponseBody
    public AjaxResult edit(@PathVariable("id") Long id)
    {
        return AjaxResult.success(categoryService.selectCategoryById(id));
    }

    /**
     * 修改保存账单分类
     */
    @ApiOperation("修改保存账单分类")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody Category category)
    {
        return toAjax(categoryService.updateCategory(category));
    }

    /**
     * 删除账单分类
     */
    @ApiOperation("删除账单分类")
    @DeleteMapping("/remove/{id}")
    @ResponseBody
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(categoryService.deleteCategoryByIds(id));
    }
}
